package edu.utdallas.taskExecutor;

import java.util.logging.Level;
import java.util.logging.Logger;

public class TaskRunner extends TaskExecutorImpl implements Runnable{
    
    Task task;
    String threadName;
    
    public TaskRunner() {
    }
    
    public TaskRunner(String name) {
        threadName = name;
    }
  
    
    @Override
    public void run() {
        Thread.currentThread().setName(threadName);
        while(true) {
            try {
                // Get task from blocking queue in static class
                task = (Task)taskExecutor.getTask();
                
            } catch (InterruptedException ex) {
                Logger.getLogger(TaskRunner.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            // execute task, might need a critical section here
            task.execute();
        }
    }
}
